from django.db import models
from django.contrib.auth.models import User, AbstractUser
from book_manage.models import AudioBook
from book_manage.models import Chapter
# Create your models here.


# User表
class UserInfo(AbstractUser):
    # id 用户表id
    id = models.AutoField(primary_key=True)
    # 帐号邮箱
    # username = models.CharField(max_length=12)
    # 密码
    # password = models.CharField(max_length=22)
    # 昵称
    # name = models.CharField(max_length=20)
    # 手机
    phone = models.CharField(max_length=20, null=True)
    # 性别
    sex = models.CharField(max_length=4, null=True)
    # 生日
    birthday = models.DateField(max_length=255, null=True)
    # 头像
    headImage = models.CharField(
        max_length=255, default='/static/head_image/tx.png')
    # 自我介绍
    info = models.CharField(max_length=255, null=True)
    # 爱好
    fun = models.CharField(max_length=40, null=True)
    # 地区
    area = models.CharField(max_length=20, null=True)
    # 会员时间
    vip = models.DateField(null=True)
    # 书币
    coin = models.DecimalField(default=0, decimal_places=0, max_digits=10)
    # 书券
    coupon = models.DecimalField(default=0, decimal_places=0, max_digits=10)


# 打卡签到
class SignIn(models.Model):
    username = models.ForeignKey(UserInfo, on_delete=models.CASCADE)
    date = models.DateField()


# 用户收藏书
class Collect(models.Model):
    user = models.ForeignKey(
        UserInfo, to_field='username', on_delete=models.CASCADE)
    bookId = models.ForeignKey(
        AudioBook, to_field='bookId', on_delete=models.CASCADE)
    date = models.DateField(null=True)


# 用户书架
class Shelf(models.Model):
    user = models.ForeignKey(
        UserInfo, to_field='username', on_delete=models.CASCADE)
    bookId = models.ForeignKey(
        AudioBook, to_field='bookId', on_delete=models.CASCADE)
    date = models.DateField(null=True)


# 评论
class Comment(models.Model):
    user = models.ForeignKey(
        UserInfo, to_field='username', on_delete=models.CASCADE)
    bookId = models.ForeignKey(
        AudioBook, to_field='bookId', on_delete=models.CASCADE)
    comment = models.CharField(max_length=255, null=True)
    date = models.CharField(null=True, max_length=20)
    score = models.DecimalField(max_digits=2, decimal_places=0, null=True)


# 点赞
class Like(models.Model):
    user = models.ForeignKey(
        UserInfo, to_field='username', on_delete=models.CASCADE)
    commentId = models.ForeignKey(
        Comment, to_field='id', on_delete=models.CASCADE)
    date = models.DateField(null=True)


# 购书按章节
class BuyChapter(models.Model):
    user = models.ForeignKey(
        UserInfo, to_field='username', on_delete=models.CASCADE)
    chapterId = models.CharField(null=False, max_length=20)
